﻿using HungryCrowdLibrary.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace HungryCrowdLibrary.Manager
{
    public class LocationManager
    {
        internal LocationData locationData;
        internal LocationData LocationData { get { return locationData = locationData ?? new LocationData(); } }

        public bool SaveChanges(Location location)
        {
            var success = false;
            using (var hctx = new HungryCrowdEntities())
            {
                hctx.Locations.Add(location);
                success = hctx.SaveChanges() > 0;
            }
            return success;
        }


        public List<Location> GetList(Expression<Func<Location, bool>> search)
        {
            var locations = new List<Location>();
            using (var hctx = new HungryCrowdEntities())
            {
                locations = hctx.Locations.Where(search).ToList<Location>();
            }
            return locations;
        }

        #region Custom ORM Methods
        public List<Location> GetList()
        {
            return LocationData.GetList();
        }

        public Location GetDetail(int locationId)
        {
            return LocationData.GetDetail(locationId);
        }
        #endregion
    }
}
